#include<iostream>
#include<cmath>
using namespace std;
int n, m ,k, x;
using ll = long long;

ll qpow(int x, int y, int z)
{
    ll ret = 1;
    // zdl:: 快速幂的魔板
    while (y)
    {
        if (y & 1) ret = ret * x % z;
        y >>= 1;
        x = x * x % z;
    }
    return ret;
}

int main()
{
    cin >> n >> m >> k >> x;
    cout << (x + m * qpow(10, k, n)) % n << endl;
    return 0;
}